package com.scoutmobmap.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Util {

  
  public static String readUrl(String urlString) {
    try {
    URL url = new URL(urlString);
    InputStreamReader isr = new InputStreamReader(url.openStream(), "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = br.readLine()) != null) {
      sb.append(line);
    }
    br.close();
    return sb.toString();
    } catch (MalformedURLException e) {
      return null;
    } catch (IOException e) {
      return null;
    }
  } 
  
  public static Document readAndParseUrl(String urlString) {
    String s = readUrl(urlString);
    return Jsoup.parse(s);
  }
}
